<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<% 
String subject = request.getParameter("subject");
String group = request.getParameter("group");
String subjectname = request.getParameter("subjectname");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<meta charset="UTF-8">
<title>Subjects</title>
<link rel="stylesheet" href="../css/normalize.css">
<link rel="stylesheet" href="../css/teacher_style.css">
<script type="text/javascript" src="../js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="../js/moment.min.js"></script>
<script type="text/javascript" src="../js/jquery-ui-1.10.4.custom.min.js"></script>
</head>
<body>
<div class="container">
    <div class="main-left">
    <div class="main-right">
        <div class="main">
					<div class="nav">
						<ul>
							<li><a id="tab" href="#">Classes</a> <span
								class="courses-button">▼</span>
								<ul class="courses-dd" id="tab">
									<c:forEach items="${teacher.subjects}" var="subject">
										<li class="course_li"><a class="course"
												href="../teacher/groupsservlet?subject=${subject.id}"> ${subject.name } </a></li>
									</c:forEach>
									
								</ul></li>
							<li><a href="../teacher">Schedule</a>
							</li>
							<li><a href="../teacher/help">Help</a>
							</li>
						</ul>
						<div class="usernav">
							<a href="#" id="account-drop" style="min-width: 110px;"> <img
								src="../images/icons/user2-16.png" alt=" " />${teacher.name } <span
								id="account-drop-down" style="float: right;">▼</span> </a>
							<ul id="drop-down">
								<li><a href="#" id="change-password">Change password</a></li>
								<li><a href="#" id="change-email">Change email</a></li>
								<li><a href="#" id="logout">Logout</a></li>
							</ul>
							<div class="clear"></div>
						</div>
						<div class="clear"></div>
					</div>
					<!-- nav end-->            
            <div class="content">
                <div class="offset">
                    <div class="left">
                        <table class="crumbs">
                            <tbody>
                                <tr>
                                    <!-- change java code here -->
                                    <td class="first">
                                        <a href="../teacher/groupsservlet?subject=<%=subject %>">
                                            <%=subject %>
                                        </a>
                                    </td>
                                    <td>→</td>
                                    <td class="last"><em><%=group%></em></td>
                                </tr>
                            </tbody>
                        </table>
                        <div class="page-left">
                            
                            <div class="export-att">
                                <a class="export-att-button" href="../teacher/groupsservlet?subject=<%=subject%>&group=<%=group%>&upload=on">
                                   Export Attendance
                                </a>
                            </div>
                            <div class="prev-date">
                                <button class="prev nohover" id="prev-date">Previous dates</button>
                                <button class="next" id="next-date">Next dates</button>
                            </div>
                            <div class="clear"></div>
                            <table class="student-list">
                                <thead>
                                    <tr>
                                        <th>Student name</th>
                                        <c:forEach items="${dates }" var="date">
                                        <th>
                                        	<c:out value="${date }"></c:out>
                                        </th>
                                        </c:forEach>
                                        
                                    </td>
                                </thead>
                                <tbody>
                                
                                <c:forEach items="${attendance}" var="item">
                                	<tr>
                                      	<td class="student-name">
                                            ${item.student }
                                        </td>
                                        <c:forEach items="${item.att }" var="oneAtt">
                                        	<td class="student-att" data-col="0">
                                            <c:out value="${oneAtt}"></c:out>
                                        	</td>
                                        </c:forEach>
                                        <div class="clear"></div>
                                    </tr>
                                </c:forEach>
                                </tbody>
                            </table>
                            <div class="clear"></div>
                        </div>
                        <div class="clear"></div>
                    </div>
                </div>
                <div class="right">
                    <div class="right-fade">
                        <div class="right-time">
									<span class="time round-3" id="time"></span>
								</div>
								<div class="right-classes">
									<h2>Your classes</h2>
									<ul class="courses_ul">
										<c:forEach items="${teacher.subjects }" var="subject">
											<li class="course_li"><a class="course"
												href="../teacher/groupsservlet?subject=<%=subject%>"> ${subject.name } </a></li>
										</c:forEach>
									</ul>
									<div class="clear"></div>
									
									<div class="clear"></div>
								</div>
                        <div class="clear"></div>
                        <div class="right-extras">
                            <h2>Support</h2>
                        </div>
                    </div>
                </div>
                <div class="clear"></div>
            </div>

        </div>
        <div class="clear"></div>
    </div>
    </div>
    <div class="clear"></div>
</div><!-- container end-->
<div class="clear"></div>
<script>
$(document).ready(function() {

    function changeColor(t, grade) {
        if (t.hasClass("yellow"))
            t.removeClass("yellow");
        if (t.hasClass("green"))
            t.removeClass("green");
        switch (grade) {
            case 1: t.addClass("yellow"); break;
            case 2: t.addClass("green"); break;
        }
    }

    $(".student-list td").each(function() {
        var t = $(this);
        if ($.isNumeric(t.text())) {
            var grade = parseInt(t.text());
            changeColor(t, grade);
            //t.text("");
        }
    });
    $(".student-list td").click(function(ev) {
        ev.preventDefault();
        var t = $(this);
        if (t.hasClass("student-att")) {
            var grade = parseInt(t.text());
            if (grade == 2)
                grade = 0;
            else 
                grade++;
            changeColor(t, grade);
            t.text(grade);
        }
        // maybe ajax here
        return false;
    });
    $("#prev-date").click(function() {
        var t = $(this);
        if (true) {
            t.removeClass("nohover");
        }
        if (t.hasClass("nohover")) {
            return false;
        }
        return false;
    });

});
</script>
</body>
</html></html>